package category.service.impl;


import blogData.entity.BlogDataVO;
import category.dao.CategoryDao;
import category.entity.CategoryVO;
import category.service.CategoryService;
import generic.page.Pages;

import java.util.List;

public class CategoryServiceImpl implements CategoryService{

    private CategoryDao categoryDao;

    private CategoryVO categoryVo;

    public void setCategoryDao(CategoryDao categoryDao) {
        this.categoryDao = categoryDao;
    }

    @Override
    public CategoryVO findCategoryVOById(Integer categoryId) {
        return this.categoryDao.findCategoryVOById(categoryId);
    }

    @Override
    public void deleteCategoryById(Integer categoryId) {
        this.categoryDao.deleteCategoryById(categoryId);
    }

    @Override
    public CategoryVO updateCategory(CategoryVO categoryVO) {
        return this.categoryDao.updateCategory(categoryVO);
    }

    @Override
    public CategoryVO addCategoryVO(BlogDataVO blogDataVO, CategoryVO categoryVO) {
        categoryVo=this.categoryDao.existsOfCategory(categoryVO,blogDataVO.getBlogDataId());
        if(categoryVo == null){
            blogDataVO.getCategoryVOs().add(categoryVO);
            categoryVO.setBlogDataVO(blogDataVO);
           return this.categoryDao.addCategoryVO(categoryVO);
        }else{
            return categoryVo;
        }
    }

    @Override
    public Pages queryForPage(Pages pages,Integer blogDataId) {
        if(pages==null){
            pages=new Pages();
        }
        return this.categoryDao.queryForPage(pages,blogDataId);
    }

    @Override
    public Integer countArticleByCategory(Integer categoryId) {
        return this.categoryDao.countArticleByCategory(categoryId);
    }

    @Override
    public List<CategoryVO> findAllCategoryByBlogData(Integer blogDataId) {
        return this.categoryDao.findAllCategoryByBlogData(blogDataId);
    }

    @Override
    public CategoryVO findCategoryByName(CategoryVO categoryVO,Integer blogDataId) {
        return this.categoryDao.existsOfCategory(categoryVO,blogDataId);
    }
}
